#
# pymoz, Python extension for the Mozilla Toolkit
# Copyright (C) 2012 Malek Hadj-Ali
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#


DEPTH     = ../../..
topsrcdir = @top_srcdir@
srcdir    = @srcdir@
VPATH     = @srcdir@


include $(DEPTH)/config/autoconf.mk


include $(topsrcdir)/extensions/pymoz/pymoz.mk


MODULE = pymoz
XPI_NAME = pymoz


PYMOZ_TARGET ?= python3
VERSION_CHECK = "import sys, platform; sys.exit(platform.python_version() < sys.argv[-1])"

ifneq ($(shell $(PYMOZ_TARGET) -c $(VERSION_CHECK) $(PYMOZ_TARGET_MINVERSION); echo $$?),0)
    $(error Aborted: pymoz requires Python >= $(PYMOZ_TARGET_MINVERSION), use 'PYMOZ_TARGET=/path/to/python3' to use an alternate Python binary)
endif


PYMOZ_CONFIG := $(PYMOZ_TARGET) $(srcdir)/pymoz_config.py

PYTHON_INCLUDES := $(shell $(PYMOZ_CONFIG) --includes)
PYTHON_LIBNAME  := $(shell $(PYMOZ_CONFIG) --libname)
PYTHON_CFLAGS   := $(shell $(PYMOZ_CONFIG) --cflags)
PYTHON_LIBS     := $(shell $(PYMOZ_CONFIG) --libs)


LIBRARY_NAME = pymoz
IS_COMPONENT = 1

FORCE_SHARED_LIB = 1
FORCE_USE_PIC = 1


CPPSRCS = pymoz.cpp \
          pyException.cpp \
          pyRuntime.cpp \
          pyWrappers.cpp \
          pyWrappers_PyJS.cpp \
          pyWrappers_JSPy.cpp \
          $(NULL)


LOCAL_INCLUDES += $(PYTHON_INCLUDES) \
                  $(NULL)


include $(topsrcdir)/config/rules.mk


CXXFLAGS += -DPYTHON_LIBNAME=\"$(PYTHON_LIBNAME)\" \
            $(PYTHON_CFLAGS) \
            $(NULL)


EXTRA_DSO_LDOPTS += $(PYTHON_LIBS) \
                    $(NSPR_LIBS) \
                    $(MOZ_COMPONENT_LIBS) \
                    $(XPCOM_GLUE_LDOPTS) \
                    $(MOZ_JS_LIBS) \
                    $(NULL)
